package com.mycc.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mycc.common.Code;
import com.mycc.common.Result;
import com.mycc.damin.TbGuides;
import com.mycc.damin.TbTicketOrders;
import com.mycc.damin.TbTourists;
import com.mycc.damin.TicketOrderDto;
import com.mycc.service.TicketOrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class TicketOrdersController {
    @Autowired
    private TicketOrdersService ticketOrdersService;

    //订购
    @PostMapping("/addTicketOrders")
    public Result addTicketOrders(@RequestBody TbTicketOrders ticketOrders) {
        boolean flag = ticketOrdersService.addTicketOrders(ticketOrders);
        if (flag) {
            return new Result(Code.ADD_OK, "ok", flag);
        } else {
            return new Result(Code.ADD_FAIL, "error", flag);
        }
    }

    //取消订单
    @GetMapping("/cancelTicketOrders")
    public Result cancelTicketOrders(@RequestParam int id, @RequestParam String newStatus) {
        boolean flag = ticketOrdersService.cancelTicketOrders(id, newStatus);
        if (flag) {
            return new Result(Code.SET_OK, "ok", flag);
        } else {
            return new Result(Code.SET_FAIL, "error", flag);
        }
    }

    //查询所有订单
    @GetMapping("/getAllTicketOrders/{pageNumber}/{pageSize}")
    public ResponseEntity<IPage<TicketOrderDto>> getTicketOrdersWithRelations(@PathVariable Integer pageNumber, @PathVariable Integer pageSize) {
        IPage<TicketOrderDto> ticketOrderPage = ticketOrdersService.getAllTicketOrders(pageNumber, pageSize);
        return ResponseEntity.ok(ticketOrderPage);
    }


    //通过id查询订单
    @GetMapping("/getTicketOrdersById/{id}")
    public Result getTicketOrdersById(@PathVariable int id) {
        TicketOrderDto ticketOrderDto = ticketOrdersService.getTicketOrdersById(id);
        if (ticketOrderDto != null) {
            return new Result(Code.SELECT_OK, "ok", ticketOrderDto);
        } else {
            return new Result(Code.SET_FAIL, "error", ticketOrderDto);
        }
    }

    //通过id修改订单
    //    @PutMapping("/updateTicketOrders")
    //    public Result updateTicketOrders(@RequestBody TbTicketOrders tbTicketOrders) {
    //        TicketOrderDto ticketOrderDto = new TicketOrderDto();
    //        ticketOrderDto.setOrderStatus(tbTicketOrders.getOrderStatus());
    //
    //        boolean flag = ticketOrdersService.updateTicketOrderById(tbTicketOrders.getId(), ticketOrderDto);
    //        if (flag) {
    //            return new Result(Code.SET_OK, "ok", flag);
    //        } else {
    //            return new Result(Code.SET_FAIL, "error", flag);
    //        }
    //    }
}
